<template>
    <div>
        <el-card class="box-card">
            <div class="text item">
                <div>
                    <el-row :gutter="15">
                        <el-col :span="11">
                            <div class="grid-content bg-purple">
                                <el-col :span="4">
                                    <div class="grid-content bg-purple">
                                        <span style="line-height: 1.7">预订时间</span>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.reservationTime == ''?'primary':''" plain @click="selectByBook('')">全部</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple-light">
                                        <el-button :type="condition.reservationTime == 'LastWeek'?'primary':''" plain @click="selectByBook('LastWeek')">上周</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.reservationTime == 'ThisDay'?'primary':''" plain @click="selectByBook('ThisDay')">今天</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple-light">
                                        <el-button :type="condition.reservationTime == 'ThisWeek'?'primary':''" plain @click="selectByBook('ThisWeek')">本周</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button type="primary" plain @click="selectByBook('')">自定义</el-button>
                                    </div>
                                </el-col>
                            </div>
                        </el-col>
                        <el-col :span="11">
                            <div class="grid-content bg-purple">
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <span style="line-height: 1.7">预抵时间</span>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.etaTiem == ''?'primary':''" plain @click="selectByEtaTime('')">全部</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple-light">
                                        <el-button :type="condition.etaTiem == 'LastWeek'?'primary':''" plain @click="selectByEtaTime('LastWeek')">上周</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.etaTiem == 'ThisDay'?'primary':''" plain @click="selectByEtaTime('ThisDay')">今天</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple-light">
                                        <el-button :type="condition.etaTiem == 'TomorrowDay'?'primary':''" plain @click="selectByEtaTime('TomorrowDay')">明天</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.etaTiem == 'AfterDay'?'primary':''" plain @click="selectByEtaTime('AfterDay')">后天</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.etaTiem == 'ThisWeek'?'primary':''" plain @click="selectByEtaTime('ThisWeek')">本周</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.etaTiem == 'NextWeek'?'primary':''" plain @click="selectByEtaTime('NextWeek')">下周</el-button>
                                    </div>
                                </el-col>
                            </div>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-col :span="4">
                                <div class="grid-content bg-purple">
                                    <span style="line-height: 1.7">预订状态</span>
                                </div>
                            </el-col>
                            <div class="grid-content bg-purple">
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button type="primary" plain>全部</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple-light">
                                        <el-button :type="condition.reservationStart == '0'?'primary':''" plain @click="selectByEtaStart('0')">正常</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button :type="condition.reservationStart == '1'?'primary':''" plain @click="selectByEtaStart('1')">取消</el-button>
                                    </div>
                                </el-col>
                            </div>
                        </el-col>
                        <el-col :span="12">
                            <div class="grid-content bg-purple">
                                <el-col :span="4">
                                    <div class="grid-content bg-purple">
                                        <span style="line-height: 1.7">预订方式</span>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button type="primary" plain>全部</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple-light">
                                        <el-button type="primary" plain>本地</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button type="primary" plain>官网</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple-light">
                                        <el-button type="primary" plain>携程</el-button>
                                    </div>
                                </el-col>
                                <el-col :span="3">
                                    <div class="grid-content bg-purple">
                                        <el-button type="primary" plain>美团</el-button>
                                    </div>
                                </el-col>
                            </div>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20">
                        <el-col :span="4">
                            <div class="grid-content bg-purple">
                                <el-col :span="24">
                                    <div class="grid-content bg-purple">
                                        <el-button type="primary" plain @click="save()">新增预订</el-button>
                                    </div>
                                </el-col>
                            </div>
                        </el-col>
                        <el-col :span="20">
                            <div class="grid-content bg-purple">
                                <el-col :span="10">
                                    <div class="grid-content bg-purple">
                                        <el-input
                                                placeholder="请输入姓名"
                                                v-model="condition.name"
                                                clearable>
                                        </el-input>
                                    </div>
                                </el-col>
                                <el-col :span="10">
                                    <div class="grid-content bg-purple-light">
                                        <el-input
                                                placeholder="请输入联系方式"
                                                v-model="condition.phone"
                                                clearable>
                                        </el-input>
                                    </div>
                                </el-col>
                                <el-col :span="4">
                                    <div class="grid-content bg-purple-light">
                                        <el-button type="primary" plain @click="select()">查询</el-button>
                                    </div>
                                </el-col>
                            </div>
                        </el-col>
                    </el-row>

                </div>
                <el-table
                        :data="datas"
                        border
                        style="width: 100%"
                        height="500">
                    <el-table-column type="expand">
                        <template slot-scope="props">
                            <el-form label-position="left" inline class="demo-table-expand">
                                <el-form-item label="预订订单号">
                                    <span>{{ props.row.reservationId }}</span>
                                </el-form-item>
                                <el-form-item label="客人姓名">
                                    <span>{{ props.row.guestName }}</span>
                                </el-form-item>
                                <el-form-item label="联系方式">
                                    <span>{{ props.row.guestPhone }}</span>
                                </el-form-item>
                                <el-form-item label="预订方式">
                                    <span>{{ props.row.paymentType }}</span>
                                </el-form-item>
                                <el-form-item label="预订时间">
                                    <span>{{ props.row.reservationDate }}</span>
                                </el-form-item>
                                <el-form-item label="预抵时间">
                                    <span>{{ props.row.arriveDate }}</span>
                                </el-form-item>
                                <el-form-item label="房间类型">
                                    <span>{{ props.row.roomType.typeName}}</span>
                                </el-form-item>
                                <el-form-item label="天数">
                                    <span>{{ props.row.dayNum }}</span>
                                </el-form-item>
                                <el-form-item label="间数">
                                    <span>{{ props.row.roomNum }}</span>
                                </el-form-item>
                                <el-form-item label="预定金">
                                    <span>{{ props.row.reservationPtice }}</span>
                                </el-form-item>
                                <el-form-item label="付款方式">
                                    <span>{{ props.row.paymentType }}</span>
                                </el-form-item>
                                <el-form-item label="订单状态">
                                    <span>{{ props.row.reservationState }}</span>
                                </el-form-item>
                                <el-form-item label="订单备注">
                                    <span>{{ props.row.reservationComment }}</span>
                                </el-form-item>
                                <!--<el-form-item label="接单员">
                                    <span>{{ props.row.staffInfo.staffName}}</span>
                                </el-form-item>-->
                            </el-form>
                        </template>
                    </el-table-column>
                    <el-table-column
                            label="预订姓名"
                            prop="guestName">
                    </el-table-column>
                    <el-table-column
                            label="联系方式"
                            prop="guestPhone">
                    </el-table-column>
                    <el-table-column
                            label="预订时间"
                            prop="reservationDate">
                    </el-table-column>
                    <el-table-column
                            label="预抵时间"
                            prop="arriveDate">
                    </el-table-column>
                    <el-table-column
                            label="房间类型"
                            prop="roomType.typeName">
                    </el-table-column>
                    <el-table-column
                            label="订单状态"
                            prop="reservationState">
                        <template slot-scope="scope">
                            <el-tag
                                    :type=success
                                    >完成</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column
                            label="操作"
                            width="100">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" icon="el-icon-edit" circle @click="update(scope.row)"></el-button>
                            <el-button size="mini" type="danger" icon="el-icon-delete" circle @click="remove(scope.row)"></el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                        @size-change="pagesize_s"
                        @current-change="page"
                        background
                        :current-page="currentPage"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="20"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="count"
                        >
                </el-pagination>
                <el-dialog title="预订" :visible.sync="dialogFormVisible">
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

                        <el-row :gutter="20">
                            <el-col :span="12"><div class="grid-content bg-purple">
                                <el-form-item label="预订人" prop="guestName">
                                    <el-input v-model="ruleForm.guestName"></el-input>
                                </el-form-item>
                            </div></el-col>
                            <el-col :span="12"><div class="grid-content bg-purple">
                                <el-form-item label="联系方式" prop="guestPhone">
                                    <el-input v-model="ruleForm.guestPhone"></el-input>
                                </el-form-item>
                            </div></el-col>
                        </el-row>

                        <el-row :gutter="20">
                            <el-col :span="8"><div class="grid-content bg-purple">
                                <el-form-item label="天数" prop="dayNum">
                                    <el-input-number controls-position="right" size="small"  v-model="ruleForm.dayNum" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
                                </el-form-item>
                            </div></el-col>
                            <el-col :span="8"><div class="grid-content bg-purple">
                                <el-form-item label="间数" prop="roomNum">
                                    <el-input-number  controls-position="right" size="small" v-model="ruleForm.roomNum" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
                                </el-form-item>
                            </div></el-col>
                            <el-col :span="8"><div class="grid-content bg-purple">
                                <el-form-item label="房间类型" prop="typeId">
                                    <el-select v-model="ruleForm.typeId" placeholder="请选择房间类型">
                                        <el-option v-for="type in roomTypes"
                                                   :label="type.typeName" :value="type.typeId"></el-option>
                                    </el-select>
                                </el-form-item>
                            </div></el-col>
                        </el-row>

                        <el-row :gutter="20">
                            <el-col :span="8"><div class="grid-content bg-purple">
                                <el-form-item label="预订类型" prop="reservationType">
                                    <el-select v-model="ruleForm.reservationType" placeholder="请选择房间类型">
                                        <el-option label="微信支付" value="微信支付"></el-option>
                                        <el-option label="支付宝支付" value="支付宝支付"></el-option>
                                        <el-option label="现金支付" value="现金支付"></el-option>
                                        <el-option label="POS机支付" value="POS机支付"></el-option>
                                        <el-option label="其他支付" value="其他支付"></el-option>
                                    </el-select>
                                </el-form-item>
                            </div></el-col>
                            <el-col :span="8"><div class="grid-content bg-purple">
                                <el-form-item label="支付方式" prop="paymentType">
                                    <el-select v-model="ruleForm.paymentType" placeholder="请选择支付方式">
                                        <el-option label="微信支付" value="微信支付"></el-option>
                                        <el-option label="支付宝支付" value="支付宝支付"></el-option>
                                        <el-option label="现金支付" value="现金支付"></el-option>
                                        <el-option label="POS机支付" value="POS机支付"></el-option>
                                        <el-option label="其他支付" value="其他支付"></el-option>
                                    </el-select>
                                </el-form-item>
                            </div></el-col>
                            <el-col :span="8"><div class="grid-content bg-purple">
                                <el-form-item label="预订金" prop="reservationPtice">
                                    <el-input v-model="ruleForm.reservationPtice"></el-input>
                                </el-form-item>
                            </div></el-col>
                        </el-row>

                        <el-form-item label="预订时间" required>
                            <el-col :span="11">
                                <el-form-item prop="reservationDate">
                                    <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.reservationDate" style="width: 100%;"></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-form-item>

                        <el-form-item label="预抵时间" required>
                            <el-col :span="11">
                                <el-form-item prop="arriveDate">
                                    <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.arriveDate" style="width: 100%;"></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="预订备注" prop="reservationComment">
                            <el-input type="textarea" v-model="ruleForm.reservationComment"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
                            <el-button @click="resetForm('ruleForm')">重置</el-button>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取 消</el-button>
                        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
                    </div>
                </el-dialog>
            </div>
        </el-card>
    </div>
</template>

<style>
    .demo-table-expand {
        font-size: 0;
    }
    .demo-table-expand label {
        width: 90px;
        color: #99a9bf;
    }
    .demo-table-expand .el-form-item {
        margin-right: 0;
        margin-bottom: 0;
        width: 50%;
    }
</style>

<script>
    export default {
        data() {
            return {
                /*查询条件*/
                condition: {
                    currPage: 1,
                    pageSize: 20,
                    name: "",
                    phone: "",
                    reservationTime: "",
                    etaTiem: "",
                    reservationStart: "",
                    reservationType:""
                },
                /*数据*/
                datas:[],
                /*总条数*/
                count: 1,
                input: '',

                /*房间类型*/
                roomTypes:[],

                /*判断谁点击 true为新增，false为修改*/
                isSaveAndUpdate: true,

                dialogFormVisible: false,
                formLabelWidth: '120px',

                ruleForm: {
                    guestName: '',
                    guestPhone: '',
                    reservationType: '',
                    reservationDate: '',
                    arriveDate: '',
                    dayNum: '',
                    roomNum: '',
                    reservationPtice: '',
                    paymentType: '',
                    reservationComment: '',
                    typeId:'',
                    staffId:''
                },
                rules: {
                    guestName: [
                        { required: true, message: '请输入预订人名称', trigger: 'blur' },
                        { min: 2, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
                    ],
                    guestPhone: [
                        { required: true, message: '请选择预订人联系方式', trigger: 'change' }
                    ],
                    typeId: [
                        { required: true, message: '请选择预订人联系方式', trigger: 'change' }
                    ],
                    reservationDate: [
                        { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
                    ],
                    arriveDate: [
                        { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
                    ],
                    roomNum: [
                        { required: true, message: '请选择活动资源', trigger: 'change' }
                    ],
                    desc: [
                        { required: true, message: '请填写活动形式', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            empty(){
                    this.ruleForm.guestName='',
                    this.ruleForm.guestPhone='',
                    this.ruleForm.reservationType= '',
                    this.ruleForm.reservationDate='',
                    this.ruleForm.arriveDate= '',
                    this.ruleForm.dayNum='',
                    this.ruleForm.roomNum='',
                    this.ruleForm.reservationPtice='',
                    this.ruleForm.paymentType='',
                    this.ruleForm.reservationComment='',
                    this.ruleForm.typeId='',
                    this.ruleForm.staffId=''
            },
            page(curr){
                this.condition.currPage =curr;
                console.log(this.condition)
                let _this = this;
                this.$axios.post('res/show',this.condition)
                    .then(function (response) {
                        _this.datas = response.data.data;
                        console.log(_this.datas);
                        _this.count = response.data.count;
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                console.log(this.condition)
            },
            pagesize_s(size){
                this.condition.pageSize = size;
                let _this = this;
                this.$axios.post('res/show',this.condition)
                    .then(function (response) {
                        _this.datas = response.data.data;
                        _this.count = response.data.count;
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },
            submitForm(formName) {
                let _this = this;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.dialogFormVisible = false;

                        let url = _this.isSaveAndUpdate?'res/save':'res/update';

                        _this.$axios.post(url,_this.ruleForm)
                            .then(function (response) {
                                _this.$message({
                                    type: 'success',
                                    message: '新增成功!'
                                });
                            })
                            .catch(function (error) {
                                _this.$message({
                                    type: 'info',
                                    message: '已取消新增'
                                });
                            });

                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            select(){
                this.refresh();
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            save(){
                this.empty();
                this.isSaveAndUpdate = true;
                let _this = this;
                this.$axios.post('roomtype/showtype')
                    .then(function (response) {
                        _this.roomTypes = response.data.data;
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                this.dialogFormVisible = true;
            },
            remove(row){
                let _this = this;
                console.log(row);
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    _this.$axios.post('res/remove/'+row.reservationId)
                        .then(function (response) {
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        })
                        .catch(function (error) {
                            _this.$message({
                                type: 'info',
                                message: '已取消删除'
                            });
                        });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            update(row){
                this.empty();
                this.addUpDate(row);
                this.isSaveAndUpdate = false;
                this.$axios.post('roomtype/showtype')
                    .then(function (response) {
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                this.dialogFormVisible = true;
            },

            refresh(){
                this.condition.currPage = 1;
                let _this = this;
                this.$axios.post('res/show',this.condition)
                    .then(function (response) {
                        _this.datas = [];
                        _this.count= [];
                        _this.datas = response.data.data;
                        _this.count = response.data.count;
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },

            addUpDate(row){
                this.ruleForm.guestName=row.guestName,
                    this.ruleForm.guestPhone=row.guestPhone,
                    this.ruleForm.reservationType= row.paymentType,
                    this.ruleForm.reservationDate=row.reservationDate,
                    this.ruleForm.arriveDate= row.arriveDate,
                    this.ruleForm.dayNum=row.dayNum,
                    this.ruleForm.roomNum=row.roomNum,
                    this.ruleForm.reservationPtice=row.reservationPtice,
                    this.ruleForm.paymentType=row.paymentType,
                    this.ruleForm.reservationComment=row.reservationComment,
                    this.ruleForm.typeId=row.typeId,
                    this.ruleForm.staffId=row.staffId
            },
            selectByBook(clo){
                this.condition.reservationTime = clo;
                this.refresh();
            },
            selectByEtaTime(clo){
                this.condition.etaTiem = clo;
                this.refresh();
            },
            selectByEtaStart(clo){
                this.condition.reservationStart = clo;
                this.refresh();
            }
        },
        created(){
            let _this = this;
            this.$axios.post('res/show',this.condition)
                .then(function (response) {
                    _this.datas = response.data.data;
                    _this.count = response.data.count;
                    console.log(_this.datas)
                    console.log(response);
                })
                .catch(function (error) {
                    console.log(error);
                });
        }
    }
</script>
